﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceModel;
using System.Text;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Ordens.Communication.Bovespa.Ordens.LoteDigitacao;
using Sinacor.UI.Bovespa.Ordens.Communication.Translator;
using Sinacor.UI.Bovespa.Ordens.Model;

namespace Sinacor.UI.Bovespa.Ordens.Communication
{
    public class LoteDigitacao : BaseCommunication
    {

        #region Construtor

        public LoteDigitacao(SessionInformation session)
            : base(session)
        {

        }

        #endregion

        #region ConsultarLoteDigitacao
        public ModelCollection<Model.BaseDigitacao> ConsultarLoteDigitacao(Model.Parameter.ConsultarNegocioLoteDigitacao pConsultarLoteDigitacao)
        {
            ILoteDigitacao servico = null;
            ModelCollection<Model.LoteDigitacao> pRetorno = null;
            List<Sinacor.UI.Bovespa.Ordens.Communication.Bovespa.Ordens.LoteDigitacao.LoteDigitacaoResponse> pRetornoComunication = null;

            Translator.TranslatorConsultarLoteDigitacaoRequest TransParamenter = new Translator.TranslatorConsultarLoteDigitacaoRequest();
            Translator.TranslatorLoteDigitacaoResponse TransResponse = new Translator.TranslatorLoteDigitacaoResponse();
            Translator.TranslatorLoteDigitacaoToBaseDigitacao TransBaseDigitacao = new Translator.TranslatorLoteDigitacaoToBaseDigitacao();

            try
            {

                using (ServiceInstance<ILoteDigitacao> serviceManager = new ServiceInstance<ILoteDigitacao>())
                {
                    servico = serviceManager.TryGetInstance(this.Session);
                    pRetornoComunication = servico.ConsultarLoteDigitacao(TransParamenter.Translate(pConsultarLoteDigitacao));
                }

                pRetorno = TransResponse.TranslateToList(pRetornoComunication);

                return TransBaseDigitacao.TranslateToList(pRetorno);
            }

            catch (Exception ex)
            {
                HandleFault(ex);
                return null;
            }
        }
        #endregion

        #region InserirLoteDgitacao
        public bool InserirLoteDigitacao(ModelCollection<Model.LoteDigitacao> pLoteDigitacao)
        {
            ILoteDigitacao Servico = null;
            bool result;

            try
            {
                using (ServiceInstance<ILoteDigitacao> serviceManager = new ServiceInstance<ILoteDigitacao>())
                {
                    Servico = serviceManager.TryGetInstance(this.Session);
                    result = Servico.Inserir(new Translator.TranslatorLoteDigitacao().TranslateToList(pLoteDigitacao));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
                return false;
            }

            return result;
        }
        #endregion

        #region ExcluirLoteDgitacao
        public bool ExcluirLoteDigitacao(ModelCollection<Model.Parameter.ExcluirLoteDigitacao> pExcluirLoteDigitacao)
        {
            ILoteDigitacao servico = null;
            bool result;

            try
            {
                using (ServiceInstance<ILoteDigitacao> serviceManager = new ServiceInstance<ILoteDigitacao>())
                {
                    servico = serviceManager.TryGetInstance(this.Session);
                    result = servico.Excluir(new Translator.TransLatorExcluirLoteDigitacao().TranslateToList(pExcluirLoteDigitacao));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
                return false;

            }

            return result;
        }
        #endregion

        #region ConsultarLoteDigitacaoMultiplo
        public bool ConsultarLoteDigitacaoMultiplo(ModelCollection<Model.Parameter.ConsultarOrdemDistribuicaoOrdemLote> plote)
        {
            ILoteDigitacao servico = null;
            bool result;

            try
            {
                using (ServiceInstance<ILoteDigitacao> serviceManager = new ServiceInstance<ILoteDigitacao>())
                {
                    servico = serviceManager.TryGetInstance(this.Session);
                    result = servico.ConsultarLoteDigitacaoMultiplo(new TranslateOrdemConsultarLoteRequest().TranslateToList(plote));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
                return false;

            }

            return result;
        }

        #endregion


    }
}
